<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
            list-style: none;
        }
        .container{
            width: 500px;
            margin:100px auto;
            height:200px;
            display: flex;
            justify-content: center;
            align-items: center;
            border:1px solid red;
            position: relative;

        }
        .arrow{
            width: 30px;
            height: 60px;
            background:grey;
            cursor: pointer;
            position: absolute;
        }
        .arrow.left{
            left: -50px;
        }
        .arrow.right{
            right:-50px;
        }
        .demo li{
            font-size:60px;
            text-align:center;
            line-height:200px;
            color:#fff;
            width: 500px;
            height:200px;

        }
        .indexes{
            display: flex;
            position: absolute;
            bottom: 10px;
        }
        .indexes li{
            background:green;
            padding:5px;
            margin:0 5px;
            border-radius: 50%;

        }
        .indexes li.active{
            background:#000;

        }

    </style>
</head>

<body>
    <div id ="app"> 
        <div class="container">
            <div @click="pre" class="arrow left"></div>
            <div class="arrow right"></div>
            <ul class="demo">
                <li v-show="i===activeIndex"  :style="{background:item}" v-for="(item,i) in imgList">
                    {{i+1}}
                </li>
            </ul>
            <ul class="indexes">
                <li @click="change(i)" v-for="(item,i) in imgList" :class="{active:i===activeIndex}"></li>
            </ul>

        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js "></script>
    <script>
     //创建Vue实例,得到 ViewModel
     var vm = new Vue({
        el: '#app',
        data() {
            return{
                activeIndex:0,
                imgList: ['red', 'blue', 'green', 'yellow']

            }
        },
        methods: {
            run(){
               this.timer=setInterval(() => {
                   if(++this.activeIndex===this.imgList.length){
                       this.activeIndex=0
                   }
                    
                }, 1000);
            },
            pre(){
                clearInterval(this.timer)
               if(--this.activeIndex < 0) {
                   this.activeIndex=this.imgList.length-1
                   this.run()
               }
            },
            next(){
                clearInterval(this.timer)
                if(++this.activeIndex===this.imgList.length){
                    this.activeIndex=0
                    this.run()
                }
            },
            change(i){
                console.log(i)
                clearInterval(this.timer)
                this.activeIndex =i
                this.run()
            }
        },
        mounted(){
            this.run()
        }
     });
    </script>
</body>

</html>